<?php $this->start('aside'); ?>
<?php echo $this->element('aside'); ?>
<?php $this->end(); ?>

<?php $this->start('top'); ?>
<?php echo $this->element('top'); ?>
<?php $this->end(); ?>

<?php $this->start('PluginStyle'); ?>
<?php echo $this->Html->css([
'/assets/data-tables-1.10.8/css/dataTables.bootstrap',
'/assets/data-tables-1.10.8/css/dataTables.responsive'
]);
?>
<?php $this->end(); ?>

<div class="row">
	<div class="col-lg-12">
		<?php echo $this->Form->create('Product',
		['action' => 'search', 'class' => 'form-horizontal']
		); ?>
		<div class="form-group">
			<?php echo $this->Form->label('Product.name', '搜索产品', ['class' => 'col-lg-2 control-label']); ?>
			<?php $searchQuery = isset($searchQuery) ? $searchQuery : ''; ?>
			<?php echo $this->Form->input('searchQuery',
			['label' => false, 'div' => 'col-lg-2', 'class' => 'form-control', 'value' => h($searchQuery)]
			); ?>
		</div>
		<div class="form-group">
			<div class="col-lg-offset-2 col-lg-2">
				<button type="submit" class="btn btn-success">搜 索</button>
				<button type="button" class="btn btn-success" onclick="location.href='/products/index'">重 置</button>
			</div>
		</div>
		<?php echo $this->Form->end(); ?>
	</div>
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				产品列表
			</div>
			<div class="panel-body">
				<div class="dataTable_wrapper">
					<table class="table table-striped table-bordered table-hover" id="dataTablesProduct">
						<thead>
						<tr>
							<th><?php echo $this->Paginator->sort(__('名称')); ?></th>
							<th>描述</th>
							<th><?php echo $this->Paginator->sort(__('创建时间')); ?></th>
							<th><?php echo $this->Paginator->sort(__('修改时间')); ?></th>
							<th>操作</th>
						</tr>
						</thead>
						<tbody>
						<?php if (!empty($products)): ?>
						<?php foreach ($products as $key => $val): ?>
						<tr>
							<td><?php echo $val['Product']['name']; ?></td>
							<td><?php echo $val['Product']['description']; ?></td>
							<td><?php echo $val['Product']['created']; ?></td>
							<td><?php echo $val['Product']['modified']; ?></td>
							<td>
								<a href="javascript:;" class="btn btn-info btn-xs btn-view"
								   data-id="<?php echo $val['Product']['id']; ?>">
									<i class="fa fa-file-text-o"></i> 查看
								</a>
								<a href="/products/edit/<?php echo $val['Product']['id']; ?>"
								   class="btn btn-success btn-xs">
									<i class="fa fa-edit"></i> 编辑
								</a>
								<a href="javascript:;" class="btn btn-danger btn-xs btn-delete"
								   data-id="<?php echo $val['Product']['id']; ?>">
									<i class="fa fa-remove"></i> 删除
								</a>
							</td>
						</tr>
						<?php endforeach; ?>
						<?php endif; ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-lg-12">
		<p class="text-danger">
			<?php echo $this->Paginator->counter(['format' => 'range']); ?>
		</p>

		<div class="pager">
			<?php
			echo $this->Paginator->prev('< ' . __('上一页'), [], null, ['class' => 'prev disabled']);
			echo $this->Paginator->next(__('下一页') . ' >', [], null, ['class' => 'next disabled']);
			?>
		</div>
	</div>
</div>

<?php $this->start('PluginScript'); ?>
<?php echo $this->Html->script([
'/assets/data-tables-1.10.8/js/jquery.dataTables.min',
'dataTables.bootstrap.min',
'/assets/layer-1.9.3/layer.js'
]);
?>
<?php $this->end(); ?>

<?php $this->start('PageScript'); ?>
<script>
	(function ($) {
		$.extend($.fn.dataTable.defaults, {
			'searching': false,
			'ordering': false,
			'pagingType': 'full_numbers'
		});
		$('#dataTablesProduct').DataTable({
			responsive: true
		});

		$('.btn-view').click(function (e) {
			e.preventDefault();
			var $id = $(this).attr('data-id');
			layer.open({
				type: 2,
				title: '产品信息',
				skin: 'layui-layer-rim', // 加上边框
				area: ['500px', '600px'], // 宽高
				content: '/products/view/' + $id
			});
		});

		$('.btn-delete').click(function (e) {
			e.preventDefault();
			var $id = $(this).attr('data-id');
			layer.confirm('您要删除这条产品数据吗？', {
				btn: ['确定', '取消']
			}, function () {
				$.post('/products/delete/' + $id, function (result) {
					if (result.status) {
						layer.msg(result.info, {icon: 1});
					} else {
						layer.msg(result.info, {icon: 2});
					}
				}, 'json');
			}, function () {
				layer.msg('您取消了删除', {shift: 6});
			});
		});
	})(jQuery);
</script>
<?php $this->end(); ?>
